﻿namespace KingerRobot.MexicoSailunMDC.Biz;
public class TemplateBiz : K8.MDCBB.Biz
{
    private const string ClassName = nameof(TemplateBiz);

    #region 配置参数
    private ParamData Param { get; set; }

    class ParamData
    {

    }
    #endregion

    #region PLC 通讯参数
    private ValueData Value { get; set; }
    class ValueData
    {

    } 
    #endregion

    #region 缓存
    private CacheData Cache { get; set; }
    class CacheData
    {

    } 
    #endregion

    #region 实时日志
    private StepData Step { get; set; }
    class StepData
    {
        private string _msg = string.Empty;
        public string StepMsg
        {
            get
            {
                return this._msg;
            }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    this._msg = string.Empty;
                    return;
                }
                this._msg = $"{ClassName}|{System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}>>{value}";
            }
        }
    }
    private void StepMsg(string msg)
    {
        this.Step.StepMsg = msg;
    }
    #endregion

    #region 文件日志（运行需要 Nlog 配置）
    private void WriteLog(string message)
    {
        K8.LSF.Client.Log(new K8.LSF.Log { Data = message });
    } 
    #endregion

    /// <summary>
    /// 和 PLC 通讯对象
    /// </summary>
    private BizData BizData { get; set; }
    public int Execute(BizData writer)
    {
        // Excute 方法外使用 BizData
        this.BizData = writer;

        // 返回参数
        var result = 0;

        this.StepMsg("实时监控日志不存储");

        this.WriteLog("以文件形式存储日志");

        // Excute 方法内直接使用 param
        var mark = writer.WriteData(new
        {
            // 下传字段值
        });

        return result;
    }

}
